/*
 * Essential-C - Essential C Libraries for Developers
 * Copyright (c) 2004-2008 Tom Bradford <tom@tbradford.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a 
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */

#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include "esc_string.h"

/* Private Types and Variables ***********************************************/


/* Public Functions **********************************************************/

char* esc_string_stralloc(esc_mem_t* mem, size_t len)
{
    return esc_mem_malloc(mem, sizeof(char) * (len + 1));
}

/*---------------------------------------------------------------------------*/

wchar_t* esc_string_wcsalloc(esc_mem_t* mem, size_t len)
{
    return esc_mem_malloc(mem, sizeof(wchar_t) * (len + 1));
}

/*---------------------------------------------------------------------------*/

char* esc_string_strdup(esc_mem_t* mem, char* str)
{
    size_t len = strlen(str);    
    char* result = esc_mem_malloc(mem, sizeof(char) * (len + 1));
    strlcpy(result, str, len);
    
    return result;
}

/*---------------------------------------------------------------------------*/

wchar_t* esc_string_wcsdup(esc_mem_t* mem, wchar_t* str)
{
    int len = wcslen(str);
    wchar_t* result = esc_mem_malloc(mem, sizeof(wchar_t) * (len + 1));
    wcslcpy(result, str, len);
    
    return result;
}
